/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package DBLayer;
import java.sql.*;
/**
 *
 * @author Stefan
 */
public class DBCity
{
    private  Connection con;
    /** Creates a new instance of getCity */
    public DBCity()
    {
      con = DBConnection.getInstance().getDBcon();
    }


public String getCityName(String postalCode)
{
    ResultSet results;
    String query="SELECT pCode, city FROM PostalCode WHERE pCode = " + postalCode;

    String returnString = "";

    try{
    Statement stmt = con.createStatement();
    stmt.setQueryTimeout(5);
    results = stmt.executeQuery(query);

    if( results.next() )
    {
        returnString = results.getString("city");
    }
    else{
        returnString = null;
    }
    }
        catch(Exception e)
        {
                System.out.println("City ikke fundet");
        }

        return returnString;

}
}
